﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Web.Security;

namespace Pakxel.SmartLogistic
{
    public partial class LoginForm : Telerik.WinControls.UI.RadForm
    {
        /// <summary>Delegado para manejar el evento onUserAuthenticated.</summary>
        public delegate void UserAuthenticated(object sender, EventArgs e);
        /// <summary>Evento para indicar cuando se ha autenticado correctamente un usuario mediante el Loginform.</summary>
        public event UserAuthenticated onUserAuthenticated;

        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            lbMsg.Text = "";
        }

        private void LoginAction_Click(object sender, EventArgs e)
        {
            if (Membership.ValidateUser(T002UserName.Text, T002Password.Text))
            {
                System.Threading.Thread.CurrentPrincipal =
                    new RolePrincipal(new System.Security.Principal.GenericIdentity(Membership.GetUser(T002UserName.Text).UserName));
                //Enviamos el evento de Autenticacion.
                if (onUserAuthenticated != null)
                    onUserAuthenticated(this, new EventArgs());
                Close(); //Cerramos el LogIn
            }
            else
                lbMsg.Text = "Usuario o contraseña incorrecta.";
        }

        private void CancelarAction_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
